![]() |
PATH![]() |
![]() ![]() |
A value of class String is a character string (an ordered series of characters) in AppleScript. For information on additional string value class types, see Unicode Text and International Text.
Strings in scripts are always surrounded by quotation marks, as in these examples:
"string"
"Rolling along, stringing a song"
"Pennsylvania 68000"
To include quotation marks in a string, you must use the two-character sequence, \" . For more information, see "Special Characters in Strings" later in this section.
Strings can have character, word, paragraph, and text elements.
The elements of a string may be different from the character, word, paragraph, and text objects of applications.
The operators that can have strings as operands are & , = , ≠ , > , ≥ , < , ≤ , Starts With, Ends With, Contains, Is Contained By, and As.
For detailed explanations and examples of how AppleScript operators treat strings, see Operators That Handle Operands of Various Classes.
You can use the following reference forms to refer to elements of strings:
You cannot use the Relative, Name, ID, or Filter reference forms.
The backslash ( \ ) and double-quote ( " ) characters have special meaning in strings. If you want to include either of these characters in a string, you must use the equivalent two-character sequence:
Backslash character | \\ |
Double-quote character | \ " |
The tab and return characters can be included in strings, or they can be represented by equivalent two-character sequences:
Tab character | \t |
Return character | \r |
When a string containing any of the two-character sequences is displayed to the user (as, for example, in a dialog box), the sequences are converted. For example, the string
"item 1\t1\ritem 2\t2"
is displayed in a dialog box as
item 1 1
item 2 2
AppleScript defines three constants for string values:
space
|
" "
|
tab
|
"\t"
|
return
|
"\r"
|
If a string represents an appropriate number, AppleScript supports coercion of the string to an integer, a number, or a real number. Similarly, any integer, number, or real number can be coerced to a string. AppleScript also supports coercion of a string to a single-item list and coercion of a list whose items can all be coerced to strings to a single concatenated string. Starting with version 1.3.7, AppleScript supports coercion of a constant, such as Monday or January, to a string.
There is no limit on the length of strings except the memory available in the computer.
To get a contiguous range of characters within a string, use the text element. For example, the value of the following statement is the string "y thi" .
get text 3 thru 7 of "Try this at home"
--result: "y thi"
The result of a similar statement using the character element instead of the text element is a list.
get characters 3 thru 7 of "Try this at home"
--result: {"y", " ", "t", "h", "i"}
You cannot set the value of an element of a string. For example, if you attempt to change the value of the first character of the string "Boris" as shown in the following example, you'll get an error.
set myName to "Boris"
set character 1 of myName to "D"
--results in an error, because you cannot set the values of
--elements of strings
However, you can modify the name by getting the last four characters and concatenating them with "D":
set myName to "boris"
set myName to "D" & (get text 2 through 5 of myName)
--result: "Doris"